package com.wms.controller;

import com.wms.common.CallBack;
import com.wms.common.Response;
import com.wms.domain.Menu;
import com.wms.domain.TableHead;
import com.wms.service.System.Systeminface;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "菜单")
@RequestMapping(path = "/Menu/")
@RestController
public class WmsSystem {

    @Autowired
    private Systeminface system;

    @ApiOperation(value="增加菜单")
    @RequestMapping(path="addMenu",method= RequestMethod.POST)
    public Response addMenu(@RequestBody Menu menu){
        return new CallBack() {
            @Override
            protected Object run() {
                return system.addMenu(menu);
            }
        }.execute();
    }


    @ApiOperation(value="查询菜单")
    @RequestMapping(path="MenuPage",method= RequestMethod.POST)
    public Response MenuPage(@RequestBody Menu menu){
        return new CallBack() {
            @Override
            protected Object run() {
                return system.getMenuPage(menu);
            }
        }.execute();

    }

    @ApiOperation(value="增加表格")
    @RequestMapping(path="addTable",method= RequestMethod.POST)
    public Response addTable(@RequestBody List<TableHead> tableHead){
        return new CallBack() {
            @Override
            protected Object run() {
                return system.addTable(tableHead);
            }
        }.execute();

    }
    @ApiOperation(value="查询表头分页")
    @RequestMapping(path="tableHeadPage",method= RequestMethod.POST)
//    @ApiImplicitParam(name = "tableKey", value = "key", required = true)
    public Response tableHeadPage(@RequestBody TableHead tableHead){
        return new CallBack() {
            @Override
            protected Object run() {
                return system.getTablePage(tableHead);
            }
        }.execute();

    }
    @ApiOperation(value="查询表头")
    @RequestMapping(path="getTableHead",method= RequestMethod.POST)
    @ApiImplicitParam(name = "tableKey", value = "tableKey", required = true)
    public Response getTableHead(final String tableKey){
        return new CallBack() {
            @Override
            protected Object run() {
                return system.getTableHead(tableKey);
            }
        }.execute();

    }

    @ApiOperation(value="删除菜单")
    @RequestMapping(path="deleteMenu",method= RequestMethod.POST)
    @ApiImplicitParam(name = "id", value = "id", required = true)
    public Response deleteMenu(final Long id){
        return new CallBack() {
            @Override
            protected Object run() {
                return system.delMenu(id);
            }
        }.execute();

    }

    @ApiOperation(value="查询options")
    @RequestMapping(path="getOptions",method= RequestMethod.GET)
    public Response getOptions(){
        return new CallBack() {
            @Override
            protected Object run() {
                return system.getOptions();
            }
        }.execute();
    }
}
